import Vue from 'vue';
import VueRouter from 'vue-router';
import NotFound from '@/views/error-page/NotFound';
import Login from '../views/login/index';
import BasicLayout from '../components/layout/BasicLayout';
import constantRouterMap from './router.config';

Vue.use(VueRouter);

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

const routes = [
  {
    path: '/404',
    name: 'NotFound',
    component: NotFound,
  },
  {
    path: '/login',
    name: '登录',
    component: Login,
  },
  {
    path: '/',
    name: 'index',
    component: BasicLayout,
    redirect: '/login',
    children: constantRouterMap,
  },
  // {
  //   path: '*',
  //   redirect: '/404',
  // },
];
const router = new VueRouter({
  // mode: 'history',
  mode: 'hash',
  base: process.env.BASE_URL,
  routes,
});

export default router;

